import java.util.Random;

public class Role {
    private String roleName;
    private int bloodType;

    public Role() {
    }

    public Role(String roleName, int bloodType) {
        this.roleName = roleName;
        this.bloodType = bloodType;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public int getBloodType() {
        return bloodType;
    }

    public void setBloodType(int bloodType) {
        this.bloodType = bloodType;
    }
    //定义一个方法用于攻击别人
    //思考：谁攻击谁？
    //Role r1 = new Role();
    //Role r2 = new Role();
    //r1。攻击(r2);
    //方法调用者去攻击参数
    public void attack(Role role) {
        //计算造成伤害1~20
        Random r = new Random();
        int hurt = r.nextInt(20)+1;
        //剩余血量
        int result = role.getBloodType()-hurt;
        //对剩余血量进行限制，如果小于零则为零
        result=result>0?result:-result;
        //修改剩余的血量
        role.setBloodType(result);
        //this 表示方法的调用者
        System.out.println(this.getRoleName()+"拿起拳头，打了"+role.getRoleName()+"一下，造成"+hurt+"点伤害，"+role.getRoleName()+"还剩下了"+result+"点血。");

    }
}
